#include
using namespace std;
class samp {
int x;
public:
samp(inx=n;}
int getx() {return x;}
};
samp A[10] ={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int i;
for(i=0; i<10; i++) cout << A[i].getx() << ' ';
n";
return 0;
Githiari answered the question on May 29, 2018 at 18:45
- Show how to allocate a float and an int by using new. Also, show how to free them by using delete.(Solved)
Show how to allocate a float and an int by using new. Also, show how to free them by using delete.
Date posted: May 29, 2018. Answers (1)
- Create a function called mag() using the following prototype that raises num to the order of magnitude specified by order.(use C++ language)
void mag(long &num, long...(Solved)
Create a function called mag() using the following prototype that raises num to the order of magnitude specified by order.(use C++ language)
void mag(long &num, long order);
For example, if num is 4 and order is 2, when mag() returns, num will be 400.Demonstrate in a program that the function works.
Date posted: May 29, 2018. Answers (1)
- The copy constructor is also involked when a function generates the temporary object that is used as the function's return value. With this in...(Solved)
The copy constructor is also involked when a function generates the temporary object that is used as the function's return value. With this in mind, consider the following output:
constructing nomally
constructing normally
constructing copy
This output was created by the following program. Explain why, and describe precisely what is occuring.
#include
using namespace std;
class myclass {
public:
myclass();
myclass(const myclass &o);
myclas f();
};
// Normal constructor
myclass::myclass()
{
cout << "Constructing normally\n";
}
// Copy constructor
myclass::myclass(const myclass &ocout << "Constructing copy\n";
}
// Return an object.
myclass myclass::f()
{
myclass temp;
return temp;
}
int main()
{
myclass obj;
obj = obj.return 0;
}
Date posted: May 29, 2018. Answers (1)
- Explain the purpose of copy constructor and how it differs from a normal constructor.
(Solved)
Explain the purpose of copy constructor and how it differs from a normal constructor.
Date posted: May 29, 2018. Answers (1)
- Given this particular defined class;
class strtype {
char *p;
int len;
public:
char *getstring() { return p;}
int getlength() { return len;}
add two constructor functions. Have the first one...(Solved)
Given this particular defined class;
class strtype {
char *p;
int len;
public:
char *getstring() { return p;}
int getlength() { return len;}
add two constructor functions. Have the first one take no parameters. Have this one allocate 255 bytes of memory (using new), initialize that memory as a null string, and give len a value of 255. Have the other constructor take two parameters. The first is the string to use for initialization and the other is the number of bytes to allocate. Have this version allocate the specified amount of memory and copy the string to that memory. Perform all necessary boundary checks and demonstrate that your constructors work by including a short program.
Date posted: May 29, 2018. Answers (1)
- Explain what is wrong with the following program and then fix it.
// This program contains an error.
#include
#include
using namespace std;
class myclass {
int *p;
public:
myclass(int i);
~myclass()...(Solved)
Explain what is wrong with the following program and then fix it.
// This program contains an error.
#include
#include
using namespace std;
class myclass {
int *p;
public:
myclass(int i);
~myclass() { delete p;}
friend int getval(myclass o);
};
myclass::myclass(int)
{
p = n;
if(!p) {
cout << "Allocation error\n";
exit(1);
}
*p = i;
}
int getval(myclass o)
{
return *o.p; // get value
}
int main()
{
myclass (2);
cout << getval (a) << " " <cout <<"\n";
cout << getval(a) << " " << getval(b);
return 0;
}
Date posted: May 29, 2018. Answers (1)
- Imagine a situation in which two classes, called pr1 and pr2, shown below, share one printer.Further imagine that other parts of your program need to...(Solved)
Imagine a situation in which two classes, called pr1 and pr2, shown below, share one printer.Further imagine that other parts of your program need to when the printer is in use by an object of either of these two classes. Create a function in C++ called inuse() that returns true when the printer is being used by either and false otherwise. Make this function a friend of both pr1 and pr2.
class pri1 {
int printing; //...
public:
pr1 () {printing = 0}
void set_print (int status) {printing = status;}
// ...
};
class pr2 {
int printing;
// ...
public:
pr2 () {printing = 0;}
void set_prt status) {printing = status; }
// ...
};
Date posted: May 29, 2018. Answers (1)
- Given this class;
class planet {
int moons;
double dist_from_sun; // in miles
double diameter;
double mass;
public:
//...
double get_ () { return disfrom_sun; }
};
Create a function called light() using c++...(Solved)
Given this class;
class planet {
int moons;
double dist_from_sun; // in miles
double diameter;
double mass;
public:
//...
double get_ () { return disfrom_sun; }
};
Create a function called light() using c++ language that takes as an argument an object of type planet and returns the number of secos that it takes light from the sun to reach the planet.(Assume that light travels at 186,000 miles per second and that dist_from_sun is specified in miles.)
Date posted: May 29, 2018. Answers (1)
- When an object of a derived class is assigned to another object of the same derived class, is the data associated with the base class...(Solved)
When an object of a derived class is assigned to another object of the same derived class, is the data associated with the base class copied? To find out, use the following two classes and write a program that demonstrates what happens.
class base {
int a;
public:
void load_a(int n) { a= n; }
int ge() { return a;}
};
class derived : public base {
int b;
public:
void load_b(int n) {b=n;}
int get_b() {return b;}
};
Date posted: May 29, 2018. Answers (1)
- Using the stack class, write a function called loadstack() that returns a stack that is already loaded with letters of the alphabet (a-z.). Assign this...(Solved)
Using the stack class, write a function called loadstack() that returns a stack that is already loaded with letters of the alphabet (a-z.). Assign this stack to another object in the calling routine and prove that it contains the alphabet. Be sure to change the stack size so it is large enough to hold the alphabet.
Date posted: May 29, 2018. Answers (1)
- Explain five good programming practices(Solved)
Explain five good programming practices.
Date posted: May 29, 2018. Answers (1)
- List five examples of softwares(Solved)
This is a question based on Introduction to Computer Systems unit in Computer science course
Date posted: May 26, 2018. Answers (1)
- List three categories of operating systems(Solved)
List three categories of operating systems.
Date posted: May 26, 2018. Answers (1)
- As a programmer, what is the significance of the Integrated Development Environment(IDE) in programming?(Solved)
As a programmer, what is the significance of the Integrated Development Environment(IDE) in programming?
Date posted: May 26, 2018. Answers (1)
- As a programmer, briefly explain why comments are used when writing a program(Solved)
As a programmer, briefly explain why comments are used when writing a program.
Date posted: May 26, 2018. Answers (1)
- Define the following terms as used in computer programming: (a.) A compiler (b.) A debugger (c.) An algorithm(Solved)
Define the following terms as used in computer programming: (a.) A compiler (b.) A debugger (c.) An algorithm
Date posted: May 26, 2018. Answers (1)
- What is computer programming?(Solved)
What is computer programming?
Date posted: May 26, 2018. Answers (1)
- Using an example, differentiate a code from a program(Solved)
Using an example, differentiate a code from a program.
Date posted: May 26, 2018. Answers (1)
- Explain three techniques of detecting deadlocks in a computer system(Solved)
Explain three techniques of detecting deadlocks in a computer system.
Date posted: May 16, 2018. Answers (1)
- Explain common types of computer networks(Solved)
Explain common types of computer networks.
Date posted: May 16, 2018. Answers (1)